﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DigitalRubyShared;
public class Level_Light_Fan : MonoBehaviour
{

    public GameLevelItem gameLevelItem;

    public GameObject rotateScaleObject;
    public GameObject rotateScaleRoot;
    private OneTouchRotateGestureRecognizer rotationGestureScale = new OneTouchRotateGestureRecognizer();
    public float totalAngleScale;


    public GameObject light1;
    public GameObject light2;

    private bool result = false;

    private void OnEnable()
    {
        FingersScript.Instance.AddGesture(rotationGestureScale);
        rotationGestureScale.StateUpdated += RotationGestureScaleUpdated;
        rotationGestureScale.PlatformSpecificView = rotateScaleObject;


    }

    private void OnDisable()
    {
        FingersScript.Instance.RemoveGesture(rotationGestureScale);
    }

    private void RotationGestureScaleUpdated(DigitalRubyShared.GestureRecognizer gesture)
    {
        if (gesture.State == GestureRecognizerState.Executing)
        {
            if (result)
                return;
            //Debug.Log(rotationGesture.RotationDegreesDelta);
            if (rotationGestureScale.RotationDegreesDelta < 0)
            {
                totalAngleScale += rotationGestureScale.RotationDegreesDelta;
                //Debug.Log(totalAngle);
                rotateScaleRoot.transform.Rotate(0.0f, 0.0f, rotationGestureScale.RotationDegreesDelta);
                JudgeResult();
            }

        }
    }



    private void JudgeResult()
    {
        if (Mathf.Abs(totalAngleScale) > 3600)
        {
            result = true;
            gameLevelItem.TriggerResult(true);
            light1.SetActive(false);
            light2.SetActive(true);
        }
    }
}


